//
// Created by shenbin on 2022/4/16.
//

#ifndef ALGORITHM_TRAINNING_C01_LC206_H
#define ALGORITHM_TRAINNING_C01_LC206_H


class LeetCode206 {
private:
    struct ListNode {
        int val;
        ListNode *next;

        ListNode() : val(0), next(nullptr) {}

        ListNode(int x) : val(x), next(nullptr) {}

        ListNode(int x, ListNode *next) : val(x), next(next) {}
    };

public:
    /**
     * 写法一
     * @param head
     * @return
     */
    ListNode reverseList(ListNode *head) {
        ListNode *last = nullptr;
        while (head != nullptr) {
            ListNode *nextHead = head->next;
            head->next = last;
            last = head;
            head = nextHead;
        }
        return last;
    }

};

#endif //ALGORITHM_TRAINNING_C01_LC206_H
